import 'package:get/get.dart';
import 'package:nyh_motorcade_app/entity/transaction_flow_details_entity.dart';
import 'package:nyh_motorcade_app/http/http_address.dart';
import 'package:nyh_motorcade_app/http/http_manager.dart';
import 'package:nyh_motorcade_app/utils/toast_utils.dart';
import 'package:nyh_motorcade_app/widgets/multi_state/multi_state_widget.dart';

class TransactionFlowDetailsController extends GetxController {
  MultiState multiState = MultiState.loading;
  String id = "";

  TransactionFlowDetailsEntity? entity;

  @override
  void onReady() {
    super.onReady();
    id = Get.arguments ?? "";
    getTransactionFlowDetails();
  }

  void onRetry() {
    multiState = MultiState.loading;
    update();
    getTransactionFlowDetails();
  }

  void getTransactionFlowDetails() {
    httpManager.post(
      Get.context,
      HttpAddress.GET_TRANSACTION_FLOW_DETAILS,
      {"id": id},
      isToast: true,
      onSuccess: (data) {
        if (data == null) {
          ToastUtils.toast("请求失败");
          multiState = MultiState.fail;
          update();
          return;
        }
        entity = TransactionFlowDetailsEntity().fromJson(data);
        multiState = MultiState.success;
        update();
      },
      onFail: (code, msg) {
        multiState = MultiState.fail;
        update();
      },
      onError: (msg) {
        multiState = MultiState.error;
        update();
      },
    );
  }
}
